home *** CD-ROM | disk | FTP | other *** search
- Path: news1.cle.ab.com!usenet
- From: don.phillips@ab.com (Donald-Anthony C. Phillips)
- Newsgroups: comp.lang.c
- Subject: Re: How do you pass along a variable argument list?
- Date: Thu, 11 Jan 1996 16:10:50 GMT
- Organization: The Allen-Bradley Co., Inc
- Distribution: inet
- Message-ID: <4d328r$vs@news1.cle.ab.com>
- References: <4d1i8v$k8h@news.mcl.bdm.com>
- NNTP-Posting-Host: abpc386.cle.ab.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- The method is as follows:
-
- int myfunc(char *myarg, ...)
-
- Yes! It's as simple as adding elipses to the end of the argument list.
-
-
- You can then step through the argument list using the <stdarg.h>
- header file which contains macros for stepping.
-
- The type 'va_list' is used to declare a varible for pointing to each
- unnamed argument. There's a macro ' va_start' which initializes your
- variable of type 'va_list' to point to the first unnamed argument.
-
- Macro 'va_arg' actually returns the next argument and steps for you
- and lastly 'va_end' does some cleanup work when your done.
-
- The 'C Programmng Language' by K&R has a complete explanation of
- variable length arguments in chapter 7.
-
-
- Donald-Anthony C. Phillips
- Programmer/Analyst
- Rockwell Automation
- ---------------------------------------
- Allen-Bradley
- don.phillips@ab.com
-
-